<div id="content">

<div id="tsanpham"><p class="tp">Kết quả tìm kiếm</p></div>
<?php
	include("include/config.php");
	include("include/lib.php");
		//xu ly chuoi tim kiem: p_category, p_name
	if (isset($_REQUEST['p_name'])) {
		$cate = $_REQUEST['p_category'];
		$str2 = "";
		if ($cate != "all")  {
			$str2 = "category.name = '$cate' AND";
		}
		$str1 = strtolower(vn_str_filter($_REQUEST['p_name']));
		$arr_str1 = explode(" ",$str1);
		$str3 = ""; $i = 1;
		foreach ($arr_str1 as $each) {
			if ($i == 1) {
				$str3 = "(product.uname LIKE '%$each%' OR subcategory.uname LIKE '%$each%' OR category.uname LIKE '%$each%'";
			} else {
				$str3 = $str3."OR product.uname LIKE '%$each%' OR subcategory.uname LIKE '%$each%' OR category.uname LIKE '%$each%'";
			}
			$i++;
		}
		$str3 = $str3.")";
		$sql=" SELECT * FROM ((subcategory JOIN category ON subcategory.parent_id = category.id) JOIN product ON product.subcategory = subcategory.id) WHERE $str2 $str3";
		$rs=mysql_query($sql);
		if($rs)
		{
			$rn=mysql_num_rows($rs);
			if($rn == 0) echo "Không tìm thấy sản phẩm tên <a style = 'color:red;'>$str1<a>";
			else
			{
			while($rw=mysql_fetch_array($rs))
				{
?>

<div class="sanpham"><a href="product.php?id=<?php echo $rw['id'] ?>"><div id="anhsp"><img class="img" src="images/product/<?php echo $rw['image'];?>" border="0"/></a></div>

	<span><?php echo $rw['name']; ?></span>
	<p style = "text-align:center;">Mã SP: <?php echo $rw['code']; ?></p>
	<p class="gia"><?php echo number_format($rw['price'],0,',','.'); ?></p>
	<a href="buy.php?id=<?php echo $rw['id'] ?>"><img src="images/buy.png" boder="0"/></a>
	</div>
<?php
				}
			}
		}
	}
?>


</div>
